
***************************************************************************************************
****                                         OUTLINE                                           ****
****___________________________________________________________________________________________****
****                                                                                           ****
****      I. Quaterly-LFS Data Cleaning                                                        ****
****      II. Cleaning CPI Data                                                                ****
****      III. Cleaning Minimum Wage Data                                                      ****
****      IV. Merging Data                                                                     ****
****         1. Merging LFS Data in Each Year                                                  ****
****         2. Merging LFS with Minimum Wage and CPI Data                                     ****
****      V. Data Adjustment                                                                   ****
****___________________________________________________________________________________________****
***************************************************************************************************

clear all
set more off
cap log close
cd "C:\Users\wie-dainn\Dropbox\Work\Pleng\Article Version"
*cd "C:\Users\jariyaj\Dropbox\Pleng's Thesis\Article Version\"

***************************************************************************************************
****      I. Quaterly-LFS Data Cleaning                                                        ****
***************************************************************************************************

*******************************

*Year2011(BC 2554)

*******************************


**2011Q1 Data Cleaning

use "Data/Raw_Data/2011/Q1_54.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_more lst_mem re_wk re_ed AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE TOTALHR G_HR INDUS_G INDUS_G1 INDUS_G2

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS 
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename ed ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename rota ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2011
gen YEARQ = 201101

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION WEIGHT AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2011/Q1_54_clean", replace


**2011Q2 Data Cleaning

use "Data/Raw_Data/2011/Q2_54.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk lst_mem re_wk re_ed AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE TOTALHR G_HR INDUS_G INDUS_G1 INDUS_G2 

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS 
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename WAGE_TYP WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename ed ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename rota ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2011
gen YEARQ = 201102

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2011/Q2_54_clean", replace


**2011Q3 Data Cleaning

use "Data/Raw_Data/2011/Q3_54.dta"

drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk lst_mem re_wk re_ed AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE TOTALHR G_HR INDUS_G INDUS_G1 INDUS_G2 AGE_G2

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS 
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename WAGE_TYP WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename ed ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename rota ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename food FOOD
rename cloth CLOTH
rename house HOUSE


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2011
gen YEARQ = 201103

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2011/Q3_54_clean", replace


**2011Q4 Data Cleaning

use "Data/Raw_Data/2011/Q4_54.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk lst_mem re_wk re_ed AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE TOTALHR G_HR INDUS_G INDUS_G1 INDUS_G2

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS 
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename WAGE_TYE WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename ed ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename rota ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2011
gen YEARQ = 201104

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2011/Q4_54_clean", replace


*******************************

*Year2012(BC 2555)

*******************************


**2012Q1 Data Cleaning

use "Data/Raw_Data/2012/Q1_55.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem occup ind1 ind2 more_wk more_hr re_more lst_mem re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr timeseries year quarter

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename TOT_HR TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2012
gen YEARQ = 201201

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2012/Q1_55_clean", replace


**2012Q2 Data Cleaning

use "Data/Raw_Data/2012/Q2_55.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem occup ind1 ind2 more_wk more_hr re_more lst_mem re_wk re_ed who AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE INDUS_G INDUS_G1 INDUS_G2 INDUS_G3 TOTALHR G_HR

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename TOT_HR TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename ea ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2012
gen YEARQ = 201202

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2012/Q2_55_clean", replace


**2012Q3 Data Cleaning

use "Data/Raw_Data/2012/Q3_55.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_no lst_mem re_wk re_ed raise_wg suit_wg effecst effecnd effecrd lay_off assist get_pay newind occ10 age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2012
gen YEARQ = 201203

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2012/Q3_55_clean", replace


**2012Q4 Data Cleaning

use "Data/Raw_Data/2012/Q4_55.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem occ1 occ2 occ3 ind1 ind2 ind3 more_wk more_hr re_nom lst_mem re_wk re_ed age_g age_g1 edu edu1 wkcode wksta wksta1 province indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr filter__

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ4 OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ed ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2012
gen YEARQ = 201204

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2012/Q4_55_clean", replace


*******************************

*Year2013(BC 2556)

*******************************


**2013Q1 Data Cleaning

use "Data/Raw_Data/2013/Q1_56.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_no lst_mem re_wk re_ed newind occ10 educa age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2013
gen YEARQ = 201301

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2013/Q1_56_clean", replace



**2013Q2 Data Cleaning

use "Data/Raw_Data/2013/Q2_56.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_no lst_mem re_wk re_ed newind occ10 educa age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2013
gen YEARQ = 201302

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2013/Q2_56_clean", replace


**2013Q3 Data Cleaning

use "Data/Raw_Data/2013/Q3_56.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_no lst_mem re_wk re_ed newind occ10 educa age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2013
gen YEARQ = 201303


destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2013/Q3_56_clean", replace


**2013Q4 Data Cleaning

use "Data/Raw_Data/2013/Q4_56.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem ind1 ind2 more_wk more_hr re_no lst_mem re_wk re_ed newind occ10 educa age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2013
gen YEARQ = 201304

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2013/Q4_56_clean", replace


*******************************

*Year2014(BC 2557)

*******************************

**2014Q1 Data Cleaning

use "Data/Raw_Data/2014/Q1_57.dta"
drop subject blank line return absent method avai re_una reno_se dr_see ever_wk re_unem dr_unem occup ind1 ind2 more_wk more_hr re_more lst_mem re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename apm AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename work EMPLOY
rename receiv RECEIVE
rename occ OCCUP
rename ind4 INDUS
rename ind5 INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amoun AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename blk_vil BLK_VIL
rename psu PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN


label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2014
gen YEARQ = 201401

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2014/Q1_57_clean", replace


**2014Q2 Data Cleaning

use "Data/Raw_Data/2014/Q2_57.dta"
drop SUBJECT BLANK LINE RETURN ABSENT METHOD AVAI RE_UNA RENO_SE DR_SEE EVER_WK RE_UNEM DR_UNEM IND1 IND2 MORE_WK MORE_HR RE_NO FOOD CLOTH HOUSE LST_MEM RE_WK RE_ED AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE INDUS_G INDUS_G1 INDUS_G2 INDUS_G3 TOTALHR G_HR

*Construct SEX code
gen SEX2 = SEX
tostring SEX2, replace
drop SEX
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = REG
tostring REG2, replace
drop REG
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = AREA
tostring AREA2, replace
drop AREA
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename CWD CWT
rename APM AMP
rename YR YEAR
rename WORK EMPLOY
rename RECEIV RECEIVE
rename OCC OCCUP
rename IND4 INDUS
rename IND5 INDUS5
rename TOT_HR TOTAL_HR
rename WAGE_TY WAGE_TYPE
rename AMOUN AMOUNT
rename OTH_MON OTHER_MONEY
rename VIL BLK_VIL
rename PSU PSU_NO
rename EA_SET ROTA_GR
rename MEMBER MEMBERS
rename RELA RELATION
rename EA ED
rename OTH_THI OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2014
gen YEARQ = 201402

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2014/Q2_57_clean", replace


**2014Q3 Data Cleaning

use "Data/Raw_Data/2014/Q3_57.dta"
drop SUBJECT BLANK LINE RETURN ABSENT METHOD AVAI RE_UNA RENO_SE DR_SEE EVER_WK RE_UNEM DR_UNEM IND1 IND2 MORE_WK MORE_HR RE_NO LST_MEM RE_WK RE_ED AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE INDUS_G INDUS_G1 INDUS_G2 INDUS_G3 TOTALHR G_HR NEWIND OCC10 EDUCA

*Construct SEX code
gen SEX2 = SEX
tostring SEX2, replace
drop SEX
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = REG
tostring REG2, replace
drop REG
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = AREA
tostring AREA2, replace
drop AREA
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename CWD CWT
rename APM AMP
rename YR YEAR
rename WORK EMPLOY
rename RECEIV RECEIVE
rename OCC OCCUP
rename IND4 INDUS
rename IND5 INDUS5
rename TOT_HR TOTAL_HR
rename WAGE_TY WAGE_TYPE
rename AMOUN AMOUNT
rename OTH_MON OTHER_MONEY
rename VIL BLK_VIL
rename PSU PSU_NO
rename EA_SET ROTA_GR
rename MEMBER MEMBERS
rename RELA RELATION
rename EA ED
rename OTH_THI OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2014
gen YEARQ = 201403

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2014/Q3_57_clean", replace


**2014Q4 Data Cleaning

use "Data/Raw_Data/2014/Q4_57.dta"
drop SUBJECT BLANK LINE RETURN ABSENT METHOD AVAI RE_UNA RENO_SE DR_SEE EVER_WK RE_UNEM DR_UNEM IND1 IND2 MORE_WK MORE_HR RE_NO LST_MEM RE_WK RE_ED AGE_G AGE_G1 EDU EDU1 WKCODE WKSTA WKSTA1 PROVINCE INDUS_G INDUS_G1 INDUS_G2 INDUS_G3 TOTALHR G_HR NEWIND OCC10 EDUCA FILTER__

*Construct SEX code
gen SEX2 = SEX
tostring SEX2, replace
drop SEX
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = REG
tostring REG2, replace
drop REG
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = AREA
tostring AREA2, replace
drop AREA
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename CWD CWT
rename APM AMP
rename YR YEAR
rename WORK EMPLOY
rename RECEIV RECEIVE
rename OCC OCCUP
rename IND4 INDUS
rename IND5 INDUS5
rename TOT_HR TOTAL_HR
rename WAGE_TY WAGE_TYPE
rename AMOUN AMOUNT
rename OTH_MON OTHER_MONEY
rename VIL BLK_VIL
rename PSU PSU_NO
rename EA_SET ROTA_GR
rename MEMBER MEMBERS
rename RELA RELATION
rename EA ED
rename OTH_THI OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2014
gen YEARQ = 201404

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2014/Q4_57_clean", replace

*******************************

*Year2015(BC 2558)

*******************************


**2015Q1 Data Cleaning

use "Data/Raw_Data/2015/Q1_58.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr filter__

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*Construct CWT code
gen CWT2 = cwt
tostring CWT2, replace
gen CWT=.
replace CWT = 10 if CWT2 == "1"
replace CWT = 11 if CWT2 == "2"
replace CWT = 12 if CWT2 == "3"
replace CWT = 13 if CWT2 == "4"
replace CWT = 14 if CWT2 == "5"
replace CWT = 15 if CWT2 == "6"
replace CWT = 16 if CWT2 == "7"
replace CWT = 17 if CWT2 == "8"
replace CWT = 18 if CWT2 == "9"
replace CWT = 19 if CWT2 == "10"
replace CWT = 20 if CWT2 == "11"
replace CWT = 21 if CWT2 == "12"
replace CWT = 22 if CWT2 == "13"
replace CWT = 23 if CWT2 == "14"
replace CWT = 24 if CWT2 == "15"
replace CWT = 25 if CWT2 == "16"
replace CWT = 26 if CWT2 == "17"
replace CWT = 27 if CWT2 == "18"
replace CWT = 30 if CWT2 == "19"
replace CWT = 31 if CWT2 == "20"
replace CWT = 32 if CWT2 == "21"
replace CWT = 33 if CWT2 == "22"
replace CWT = 34 if CWT2 == "23"
replace CWT = 35 if CWT2 == "24"
replace CWT = 36 if CWT2 == "25"
replace CWT = 37 if CWT2 == "26"
replace CWT = 38 if CWT2 == "27"
replace CWT = 39 if CWT2 == "28"
replace CWT = 40 if CWT2 == "29"
replace CWT = 41 if CWT2 == "30"
replace CWT = 42 if CWT2 == "31"
replace CWT = 43 if CWT2 == "32"
replace CWT = 44 if CWT2 == "33"
replace CWT = 45 if CWT2 == "34"
replace CWT = 46 if CWT2 == "35"
replace CWT = 47 if CWT2 == "36"
replace CWT = 48 if CWT2 == "37"
replace CWT = 49 if CWT2 == "38"
replace CWT = 50 if CWT2 == "39"
replace CWT = 51 if CWT2 == "40"
replace CWT = 52 if CWT2 == "41"
replace CWT = 53 if CWT2 == "42"
replace CWT = 54 if CWT2 == "43"
replace CWT = 55 if CWT2 == "44"
replace CWT = 56 if CWT2 == "45"
replace CWT = 57 if CWT2 == "46"
replace CWT = 58 if CWT2 == "47"
replace CWT = 60 if CWT2 == "48"
replace CWT = 61 if CWT2 == "49"
replace CWT = 62 if CWT2 == "50"
replace CWT = 63 if CWT2 == "51"
replace CWT = 64 if CWT2 == "52"
replace CWT = 65 if CWT2 == "53"
replace CWT = 66 if CWT2 == "54"
replace CWT = 67 if CWT2 == "55"
replace CWT = 70 if CWT2 == "56"
replace CWT = 71 if CWT2 == "57"
replace CWT = 72 if CWT2 == "58"
replace CWT = 73 if CWT2 == "59"
replace CWT = 74 if CWT2 == "60"
replace CWT = 75 if CWT2 == "61"
replace CWT = 76 if CWT2 == "62"
replace CWT = 77 if CWT2 == "63"
replace CWT = 80 if CWT2 == "64"
replace CWT = 81 if CWT2 == "65"
replace CWT = 82 if CWT2 == "66"
replace CWT = 83 if CWT2 == "67"
replace CWT = 84 if CWT2 == "68"
replace CWT = 85 if CWT2 == "69"
replace CWT = 86 if CWT2 == "70"
replace CWT = 90 if CWT2 == "71"
replace CWT = 91 if CWT2 == "72"
replace CWT = 92 if CWT2 == "73"
replace CWT = 93 if CWT2 == "74"
replace CWT = 94 if CWT2 == "75"
replace CWT = 95 if CWT2 == "76"
replace CWT = 96 if CWT2 == "77"
drop CWT2 cwt

*Construct MONTH code
gen MONTH2 = mounth
tostring MONTH2, replace
gen MONTH=.
replace MONTH = 1 if MONTH2 == "1"
replace MONTH = 2 if MONTH2 == "2"
replace MONTH = 3 if MONTH2 == "3"
drop MONTH2 mounth

*Construct MARITAL code
gen MARITAL2 = marital
tostring MARITAL2, replace
gen MARITAL=.
replace MARITAL = 1 if MARITAL2 == "1"
replace MARITAL = 2 if MARITAL2 == "2"
replace MARITAL = 3 if MARITAL2 == "3"
replace MARITAL = 4 if MARITAL2 == "4"
replace MARITAL = 5 if MARITAL2 == "5"
replace MARITAL = 6 if MARITAL2 == "6"
drop MARITAL2 marital

*Construct EMPLOY code
gen EM2 = wk_7day
tostring EM2, replace
gen EMPLOY=.
replace EMPLOY = 1 if EM2 == "1"
replace EMPLOY = 2 if EM2 == "2"
drop EM2 wk_7day

*Construct RECEIVE code
gen R2 = receive
tostring R2, replace
gen RECEIVE=.
replace RECEIVE = 1 if R2 == "1"
replace RECEIVE = 2 if R2 == "2"
drop R2 receive

*Construct SIZE code
gen S2 = size
tostring S2, replace
gen SIZE=.
replace SIZE = 1 if S2 == "1"
replace SIZE = 2 if S2 == "2"
replace SIZE = 3 if S2 == "3"
replace SIZE = 4 if S2 == "4"
replace SIZE = 5 if S2 == "5"
replace SIZE = 6 if S2 == "6"
replace SIZE = 7 if S2 == "7"
replace SIZE = 9 if S2 == "8"
drop S2 size

*Construct WAGE_TYPE code
gen W2 = wage_ty
tostring W2, replace
gen WAGE_TYPE=.
replace WAGE_TYPE = 1 if W2 == "1"
replace WAGE_TYPE = 2 if W2 == "2"
replace WAGE_TYPE = 3 if W2 == "3"
replace WAGE_TYPE = 4 if W2 == "4"
replace WAGE_TYPE = 5 if W2 == "5"
replace WAGE_TYPE = 6 if W2 == "6"
replace WAGE_TYPE = 7 if W2 == "7"
drop W2 wage_ty

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename amp AMP
rename tmb TMB
rename yr YEAR
rename age AGE
rename grade_a GRADE_A
rename grade_b GRADE_B
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2015
gen YEARQ = 201501

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2015/Q1_58_clean", replace


**2015Q2 Data Cleaning

use "Data/Raw_Data/2015/Q2_58.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr filter__ province

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename mounth MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2015
gen YEARQ = 201502

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2015/Q2_58_clean", replace


**2015Q3 Data Cleaning

use "Data/Raw_Data/2015/Q3_58.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2


*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename mounth MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2015
gen YEARQ = 201503

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2015/Q3_58_clean", replace


**2015Q4 Data Cleaning

use "Data/Raw_Data/2015/Q4_58.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 PROVINCE indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*Construct CWT code
gen CWT2 = cwd
tostring CWT2, replace
gen CWT=.
replace CWT = 10 if CWT2 == "1"
replace CWT = 11 if CWT2 == "2"
replace CWT = 12 if CWT2 == "3"
replace CWT = 13 if CWT2 == "4"
replace CWT = 14 if CWT2 == "5"
replace CWT = 15 if CWT2 == "6"
replace CWT = 16 if CWT2 == "7"
replace CWT = 17 if CWT2 == "8"
replace CWT = 18 if CWT2 == "9"
replace CWT = 19 if CWT2 == "10"
replace CWT = 20 if CWT2 == "11"
replace CWT = 21 if CWT2 == "12"
replace CWT = 22 if CWT2 == "13"
replace CWT = 23 if CWT2 == "14"
replace CWT = 24 if CWT2 == "15"
replace CWT = 25 if CWT2 == "16"
replace CWT = 26 if CWT2 == "17"
replace CWT = 27 if CWT2 == "18"
replace CWT = 30 if CWT2 == "19"
replace CWT = 31 if CWT2 == "20"
replace CWT = 32 if CWT2 == "21"
replace CWT = 33 if CWT2 == "22"
replace CWT = 34 if CWT2 == "23"
replace CWT = 35 if CWT2 == "24"
replace CWT = 36 if CWT2 == "25"
replace CWT = 37 if CWT2 == "26"
replace CWT = 38 if CWT2 == "27"
replace CWT = 39 if CWT2 == "28"
replace CWT = 40 if CWT2 == "29"
replace CWT = 41 if CWT2 == "30"
replace CWT = 42 if CWT2 == "31"
replace CWT = 43 if CWT2 == "32"
replace CWT = 44 if CWT2 == "33"
replace CWT = 45 if CWT2 == "34"
replace CWT = 46 if CWT2 == "35"
replace CWT = 47 if CWT2 == "36"
replace CWT = 48 if CWT2 == "37"
replace CWT = 49 if CWT2 == "38"
replace CWT = 50 if CWT2 == "39"
replace CWT = 51 if CWT2 == "40"
replace CWT = 52 if CWT2 == "41"
replace CWT = 53 if CWT2 == "42"
replace CWT = 54 if CWT2 == "43"
replace CWT = 55 if CWT2 == "44"
replace CWT = 56 if CWT2 == "45"
replace CWT = 57 if CWT2 == "46"
replace CWT = 58 if CWT2 == "47"
replace CWT = 60 if CWT2 == "48"
replace CWT = 61 if CWT2 == "49"
replace CWT = 62 if CWT2 == "50"
replace CWT = 63 if CWT2 == "51"
replace CWT = 64 if CWT2 == "52"
replace CWT = 65 if CWT2 == "53"
replace CWT = 66 if CWT2 == "54"
replace CWT = 67 if CWT2 == "55"
replace CWT = 70 if CWT2 == "56"
replace CWT = 71 if CWT2 == "57"
replace CWT = 72 if CWT2 == "58"
replace CWT = 73 if CWT2 == "59"
replace CWT = 74 if CWT2 == "60"
replace CWT = 75 if CWT2 == "61"
replace CWT = 76 if CWT2 == "62"
replace CWT = 77 if CWT2 == "63"
replace CWT = 80 if CWT2 == "64"
replace CWT = 81 if CWT2 == "65"
replace CWT = 82 if CWT2 == "66"
replace CWT = 83 if CWT2 == "67"
replace CWT = 84 if CWT2 == "68"
replace CWT = 85 if CWT2 == "69"
replace CWT = 86 if CWT2 == "70"
replace CWT = 90 if CWT2 == "71"
replace CWT = 91 if CWT2 == "72"
replace CWT = 92 if CWT2 == "73"
replace CWT = 93 if CWT2 == "74"
replace CWT = 94 if CWT2 == "75"
replace CWT = 95 if CWT2 == "76"
replace CWT = 96 if CWT2 == "77"
drop CWT2
drop cwd


*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename amp AMP
rename tmb TMB
rename mounth MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2015
gen YEARQ = 201504

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2015/Q4_58_clean", replace


*******************************

*Year2016(BC 2559)

*******************************


**2016Q1 Data Cleaning

use "Data/Raw_Data/2016/Q1_59.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr PROVINCE f9_year f9_month

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename mounth MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename type TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename rela RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename cloth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=1
label var Q "Quarter"
replace YEAR=2016
gen YEARQ = 201601

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2016/Q1_59_clean", replace


**2016Q2 Data Cleaning

use "Data/Raw_Data/2016/Q2_59.dta"

drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr PROVINCE f9_year f9_month a_gr filter__

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename tpye TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename ralation RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename colth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=2
label var Q "Quarter"
replace YEAR=2016
gen YEARQ = 201602

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2016/Q2_59_clean", replace


**2016Q3 Data Cleaning

use "Data/Raw_Data/2016/Q3_59.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr PROVINCE f9_year f9_month

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename tpye TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename ralation RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename colth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=3
label var Q "Quarter"
replace YEAR=2016
gen YEARQ = 201603

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2016/Q3_59_clean", replace


**2016Q4 Data Cleaning

use "Data/Raw_Data/2016/Q4_59.dta"
drop subject line return absent method aviala re_una reno_se dr_se ever_wk re_unem dr_unem occup1 occup2 occup3 ind1 ind2 ind3 more_wk more_hr re_no lst_m re_wk re_ed who age_g age_g1 edu edu1 wkcode wksta wksta1 indus_g indus_g1 indus_g2 indus_g3 totalhr g_hr PROVINCE f9_year f9_month

*Construct SEX code
gen SEX2 = sex
tostring SEX2, replace
drop sex
gen SEX=.
replace SEX = 1 if SEX2 == "1"
replace SEX = 2 if SEX2 == "2"
drop SEX2

*Construct REG code
gen REG2 = reg
tostring REG2, replace
drop reg
gen REG=.
replace REG = 1 if REG2 == "1"
replace REG = 2 if REG2 == "2"
replace REG = 3 if REG2 == "3"
replace REG = 4 if REG2 == "4"
replace REG = 5 if REG2 == "5"
drop REG2

*AREA
gen AREA2 = area
tostring AREA2, replace
drop area
gen AREA =.
replace AREA = 1 if AREA2 == "1"
replace AREA = 2 if AREA2 == "2"
drop AREA2

rename cwd CWT
rename amp AMP
rename tmb TMB
rename month MONTH
rename yr YEAR
rename age AGE
rename marital MARITAL
rename grade_a GRADE_A
rename grade_b GRADE_B
rename wk_7day EMPLOY
rename receive RECEIVE
rename occup OCCUP
rename ind4 INDUS
rename indus INDUS5
rename size SIZE 
rename main_hr MAIN_HR
rename other_hr OTHER_HR
rename tot_hr TOTAL_HR
rename wage_ty WAGE_TYPE
rename amount AMOUNT
rename approx APPROX
rename bonus BONUS
rename ot OT
rename oth_mon OTHER_MONEY
rename weight WEIGHT
rename ea ED
rename vil BLK_VIL
rename psu_no PSU_NO
rename ea_set ROTA_GR
rename samset SAMSET
rename hh_no HH_NO
rename tpye TYPE
rename member MEMBERS
rename listing LISTING
rename enum ENUM
rename no NO
rename ralation RELATION
rename status STATUS
rename seeking SEEKING
rename finding FINDING
rename food FOOD
rename colth CLOTH
rename house HOUSE
rename oth_thi OTH_THIN

label var CWT "Province"
label var AMP "Ampher"
label var TMB "Tambon"
label var MONTH "Data Collected Month"
label var YEAR "Data Collected Year"
label var MARITAL "Marital Status"
label var GRADE_A "Education level of people who is studying"
label var GRADE_B "Education level of graduated"
label var EMPLOY "Dummy of Working/Employ or not during this 1 week"
label var RECEIVE "Dummy of unemploy with or without income"
label var OCCUP "Occupation Code"
label var INDUS "Industry Code"
label var INDUS5 "5 Digit Industry Code"
label var SIZE "Size of Business"
label var MAIN_HR "Main Working Hour"
label var OTHER_HR "Other Working Hour"
label var TOTAL_HR "Total Working Hour"
label var WAGE_TYPE "Wage Unit (per HR/DAY/..)"
label var AMOUNT "Wage per Wage Unit"
label var APPROX "Approx Wage per Month"
label var BONUS "Bonus per Year during this 12 months"
label var OT "Wage from OT per Month during this 30 day"
label var OTHER_MONEY "Other Income in this 30 days"
label var SEX "Sex"
label var REG "Region"

gen Q=4
label var Q "Quarter"
replace YEAR=2016
gen YEARQ = 201604

destring, replace

order YEAR Q YEARQ MONTH REG CWT AMP TMB SEX AGE MARITAL GRADE_A GRADE_B EMPLOY RECEIVE OCCUP INDUS SIZE MAIN_HR OTHER_HR TOTAL_HR WAGE_TYPE AMOUNT APPROX BONUS OT OTHER_MONEY AREA ED BLK_VIL PSU_NO ROTA_GR SAMSET HH_NO TYPE MEMBERS LISTING ENUM NO RELATION

save "Data/Intermediates/2016/Q4_59_clean", replace

***************************************************************************************************
****      II. Cleaning CPI Data                                                                ****
***************************************************************************************************

import excel "Data\Raw_Data\CPI\CPI_Clean.xlsx", sheet("CPI_Monthly_Clean") firstrow clear

reshape long _, i(CWT) j(YEARQ)
rename _ cpi
drop C D REG

lab var cpi "CPI by province"


save "Data/Intermediates/CPI_Clean.dta" ,replace

***************************************************************************************************
****      III. Cleaning Minimum Wage Data                                                      ****
***************************************************************************************************

*Quarterly
import excel "Data/Raw_Data/Minimum Wage/Minimum Wage_Clean.xlsx", sheet("Sheet1") firstrow clear

drop A C 
rename D province_thai
reshape long _, i(CWT) j(YEARQ)
rename _ MW
     
lab var MW "Minimum Wage"

save "Data/Intermediates/MW_CleanQ.dta", replace

*Yearly

import excel "Data/Raw_Data/Minimum Wage/Minimum Wage_Clean.xlsx", sheet("Sheet1") firstrow clear

drop A C 
rename D province_thai
reshape long _, i(CWT) j(YEARQ)
rename _ MW

lab var MW "Minimum Wage"

tostring YEARQ,  generate(YEARQ_)
gen YEAR = substr(YEARQ_, 1, 4)
destring YEAR, replace
drop YEARQ_ 

save "Data/Intermediates/MW_CleanY.dta", replace


*pMW

import excel "Data/Raw_Data/Minimum Wage/Minimum Wage_CWT.xlsx", sheet("Sheet1") firstrow clear

drop A C 
rename D province_thai
reshape long _, i(CWT) j(YEAR)
rename _ pMW

lab var pMW "Average Provincial Minimum Wage by Year"

save "Data/Intermediates/MW_Clean_CWT.dta", replace

***************************************************************************************************
****      V. Merging Data                                                                      ****
****         1. Merging LFS Data in Each Year                                                  ****
***************************************************************************************************

****************************

*2011

****************************

use "Data/Intermediates/2011/Q1_54_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2011/Q2_54_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2011.dta", replace

use "Data/merged2011.dta"
merge m:m YEARQ using "Data/Intermediates/2011/Q3_54_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2011.dta", replace

use "Data/merged2011.dta"
merge m:m YEARQ using "Data/Intermediates/2011/Q4_54_clean.dta", force
/*tab _merge*/
drop _merge more_hr finding re_more
save "Data/merged2011.dta", replace

****************************

*2012

****************************

use "Data/Intermediates/2012/Q1_55_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2012/Q2_55_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2012.dta", replace

use "Data/merged2012.dta"
merge m:m YEARQ using "Data/Intermediates/2012/Q3_55_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2012.dta", replace

use "Data/merged2012.dta"
merge m:m YEARQ using "Data/Intermediates/2012/Q4_55_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2012.dta", replace

****************************

*2013

****************************

use "Data/Intermediates/2013/Q1_56_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2013/Q2_56_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2013.dta", replace

use "Data/merged2013.dta"
merge m:m YEARQ using "Data/Intermediates/2013/Q3_56_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2013.dta", replace

use "Data/merged2013.dta"
merge m:m YEARQ using "Data/Intermediates/2013/Q4_56_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2013.dta", replace

****************************

*2014

****************************

use "Data/Intermediates/2014/Q1_57_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2014/Q2_57_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2014.dta", replace

use "Data/merged2014.dta"
merge m:m YEARQ using "Data/Intermediates/2014/Q3_57_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2014.dta", replace

use "Data/merged2014.dta"
merge m:m YEARQ using "Data/Intermediates/2014/Q4_57_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2014.dta", replace

****************************

*2015

****************************

use "Data/Intermediates/2015/Q1_58_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2015/Q2_58_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2015.dta", replace

use "Data/merged2015.dta"
merge m:m YEARQ using "Data/Intermediates/2015/Q3_58_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2015.dta", replace

use "Data/merged2015.dta"
merge m:m YEARQ using "Data/Intermediates/2015/Q4_58_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2015.dta", replace

****************************

*2016

****************************

use "Data/Intermediates/2016/Q1_59_clean.dta"
merge m:m YEARQ using "Data/Intermediates/2016/Q2_59_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2016.dta", replace

use "Data/merged2016.dta"
merge m:m YEARQ using "Data/Intermediates/2016/Q3_59_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2016.dta", replace

use "Data/merged2016.dta"
merge m:m YEARQ using "Data/Intermediates/2016/Q4_59_clean.dta", force
/*tab _merge*/
drop _merge 
save "Data/merged2016.dta", replace

***************************************************************************************************
****         2. Merging LFS with Minimum Wage and CPI Data                                     ****
***************************************************************************************************

use "Data/merged2011.dta"
merge m:m YEAR using "Data/merged2012", force
/*tab _merge*/
drop _merge 
save "merged.dta", replace

use "merged.dta"
merge m:m YEAR using "Data/merged2013", force
/*tab _merge*/
drop _merge 
save "merged.dta", replace

use "merged.dta"
merge m:m YEAR using "Data/merged2014", force
/*tab _merge*/
drop _merge 
save "merged.dta", replace

use "merged.dta"
merge m:m YEAR using "Data/merged2015", force
/*tab _merge*/
drop _merge 
save "merged.dta", replace

use "merged.dta"
merge m:m YEAR using "Data/merged2016", force
/*tab _merge*/
drop _merge 
save "merged.dta", replace

destring, replace
save "merged.dta", replace

use "merged.dta" 
merge m:m CWT YEARQ using "Data/Intermediates/MW_CleanQ.dta", force
/*tab _merge*/
drop _merge
save "merged.dta", replace

use "merged.dta" 
merge m:m CWT YEAR using "Data/Intermediates/MW_CleanY.dta", force
drop _merge
save "merged.dta", replace

use "merged.dta" 
merge m:m CWT YEAR using "Data/Intermediates/MW_Clean_CWT.dta", force
drop _merge
save "merged.dta", replace

use "merged.dta" 
merge m:m CWT YEARQ using "Data/Intermediates/CPI_Clean.dta", force
drop _merge
save "merged.dta", replace

***************************************************************************************************
****      VI. Data Adjustments                                                                 ****
***************************************************************************************************

use "merged.dta"                         

drop if YEARQ == 202103
drop if YEARQ == 202104
drop if YEARQ == 200601 & CWT == 38
drop if YEARQ == 200602 & CWT == 38
drop if YEARQ == 200603 & CWT == 38
drop if YEARQ == 200604 & CWT == 38
drop if YEARQ == 200701 & CWT == 38
drop if YEARQ == 200702 & CWT == 38
drop if YEARQ == 200703 & CWT == 38
drop if YEARQ == 200704 & CWT == 38
drop if YEARQ == 200801 & CWT == 38
drop if YEARQ == 200802 & CWT == 38
drop if YEARQ == 200803 & CWT == 38
drop if YEARQ == 200804 & CWT == 38
drop if YEARQ == 200901 & CWT == 38
drop if YEARQ == 200902 & CWT == 38
drop if YEARQ == 200903 & CWT == 38
drop if YEARQ == 200904 & CWT == 38
drop if YEARQ == 201001 & CWT == 38
drop if YEARQ == 201002 & CWT == 38
drop if YEARQ == 201003 & CWT == 38
drop if YEARQ == 201004 & CWT == 38
drop if YEARQ == 201101 & CWT == 38
drop if YEARQ == 201102 & CWT == 38
drop if YEARQ == 201103 & CWT == 38
drop if YEARQ == 201104 & CWT == 38

*Construct STATUS code
gen STATUS2 = STATUS
tostring STATUS2, replace
drop STATUS
gen STATUS=.
replace STATUS = 1 if STATUS2 == "1"
replace STATUS = 2 if STATUS2 == "2"
replace STATUS = 3 if STATUS2 == "3"
replace STATUS = 4 if STATUS2 == "4"
replace STATUS = 5 if STATUS2 == "5"
replace STATUS = 6 if STATUS2 == "6"
replace STATUS = 7 if STATUS2 == "7"
replace STATUS = 8 if STATUS2 == "8"
drop STATUS2

rename YEAR year
rename Q q
rename YEARQ yearq
rename MONTH month
rename REG region
rename CWT province
rename AMP district
rename TMB sub_district
rename SEX sex
rename AGE age
rename MARITAL marital
rename EMPLOY employ
rename RECEIVE receive
rename OCCUP occup
rename INDUS industry
rename SIZE b_size
rename MAIN_HR main_hr
rename OTHER_HR other_hr
rename TOTAL_HR total_hr
rename WAGE_TYPE wage_type
rename AMOUNT amount
rename APPROX wage
rename BONUS bonus
rename OT ot
rename OTHER_MONEY other_money
rename WEIGHT weight
rename INDUS5 indus5
rename STATUS status
rename AREA area
rename MEMBERS member

gen wage_day=.
replace wage_day = amount*(main_hr/5) if wage_type == 1
replace wage_day = amount if wage_type == 2
replace wage_day = amount/5 if wage_type == 3
replace wage_day = amount/20 if wage_type == 4
replace wage_day = amount if wage_type == 5
replace wage_day = amount if wage_type == 6
replace wage_day = amount if wage_type == 7
lab var wage_day "Wage per day"

gen wage_month=.
replace wage_month = amount*(main_hr/5)*20 if wage_type == 1
replace wage_month = amount*20 if wage_type == 2
replace wage_month = amount*4.3 if wage_type == 3
replace wage_month = wage if wage_type == 4
replace wage_month = wage if wage_type == 5
replace wage_month = wage if wage_type == 6
replace wage_month = wage if wage_type == 7
lab var wage_month "Wage per month"

gen lnwage_month = ln(wage_month)
drop wage
replace employ = 0 if employ == 2

gen regworker = 0
replace regworker = 1 if main_hr >= 38
lab var regworker "Regular Worker if main_hr >= 38 per week"

**Education
gen EDUG = substr(string(GRADE_B), 1, 1)
destring, replace

*None
gen NEDU= inlist(EDUG, 0) 
replace NEDU = 1 if GRADE_A == 0
replace NEDU = 1 if GRADE_B == 0
*Less than primary & elementary
generate ELEM = inlist(GRADE_B, 110, 211, 212, 213, 214, 215, 216, 217, 218, 219, 241, 242, 243, 244, 245, 246, 247, 248, 249, 251, 252, 253, 254, 255, 256, 1, 2, 3, 4, 5, 6, 7, 8, 9)
*Primary Education
generate PRI = inlist(GRADE_B, 210, 240, 250, 10, 12, 13, 14, 35, 37, 38)

*Secondary Education (All)
generate SEC = inlist(EDUG, 3, 4) | inlist(GRADE_B, 15, 17, 18, 36, 39, 40, 41, 19,21,23,24,25,26,27,46,48,51,52,53,54) 
*Lower Secondary Education
generate LSEC = inlist(EDUG, 3) | inlist(GRADE_B, 15, 17, 18, 36, 39, 40, 41) 
*Upper Secondary Education
generate USEC = inlist(EDUG, 4) | inlist(GRADE_B,19,21,23,24,25,26,27,46,48,51,52,53,54,11,16,20,29,42,43,44,45,47,49)
*Diploma Level
generate DIP = inlist(EDUG, 5) | inlist(GRADE_B,22)

*University Education (All)
generate UNI = inrange(EDUG, 6, 8)

*Bachelor Degree Education
generate BACHELOR = inlist(EDUG, 6)

*Master Degree Education
generate MASTER = inlist(EDUG, 7) | inlist(GRADE_B,32)
*Doctoral Degree Education
generate DOCTORAL = inlist(EDUG, 8) | inlist(GRADE_B,31,33)
*Other Education
generate OTHEREDU = inlist(EDUG, 9)


gen edu_label =.
replace edu_label = 0 if NEDU == 1
replace edu_label = 1 if ELEM == 1
replace edu_label = 2 if PRI == 1
replace edu_label = 3 if LSEC == 1
replace edu_label = 4 if USEC == 1
replace edu_label = 5 if DIP == 1
replace edu_label = 6 if BACHELOR == 1
replace edu_label = 7 if MASTER == 1
replace edu_label = 8 if DOCTORAL == 1
replace edu_label = 9 if UNI == 1
replace edu_label = 10 if OTHEREDU == 1
label variable edu_label "Education Label"
label define edug 0 "No Education" 1 "Less than Primary & Elementary Education" 2 "Primary Education Graduated" 3 "Lower Secondary Education Graduated" 4 "Upper Secondary Education Graduated" 5 "Diploma Level Graduated" 6 "Bachelor Degree Graduated" 7 "Master Degree Graduated" 8 "Doctoral Degree Graduated" 9 "University Education Graduated (All)" 10 "Other Education"
label values edu_label edug

**Year of Schooling [yos] GRADE_A 1-49
gen yos=.
replace yos = 0 if edu_label == 0
replace yos = 1 if GRADE_A == 111 | inrange(GRADE_B, 1, 9)| inrange(GRADE_A, 1, 9)
replace yos = 3 if GRADE_B == 110 | inlist(GRADE_A, 211, 250, 251)
replace yos = 4 if inlist(GRADE_B, 211, 251) | inlist(GRADE_A, 212, 241, 252)
replace yos = 5  if inlist(GRADE_B, 212, 241, 252) | inlist(GRADE_A, 213, 253)
replace yos = 6  if inlist(GRADE_B, 213, 253) | inlist(GRADE_A, 214, 242, 254)
replace yos = 7  if inlist(GRADE_B, 214, 242, 254) | inlist(GRADE_A, 215, 255)
replace yos = 8  if inlist(GRADE_B, 215, 219, 249, 255) | inlist(GRADE_A, 216, 243, 249, 256, 259)
replace yos = 9 if inlist(GRADE_B, 210, 240, 250,10, 35, 37, 38, 17,12,13, 14) | inlist(GRADE_A, 216, 243, 256, 311, 331, 351,10, 35, 37, 38, 17,12,13, 14)
replace yos = 10  if inlist(GRADE_B == 214, 311, 321, 331, 351) | inlist(GRADE_A, 312, 332, 341, 352)
replace yos = 11 if inlist(GRADE_B == 214, 312, 319, 322, 329, 332, 339, 341, 349, 352, 359) | inlist(GRADE_A, 313, 319, 333, 339, 342, 339, 353, 359)
replace yos = 12  if inlist(GRADE_B, 310, 320, 330, 340, 350, 313, 323, 333, 342, 353,15, 17, 18, 36, 39, 40, 41) | inlist(GRADE_A, 411, 421, 431, 441, 451, 461,15, 17, 18, 36, 39, 40, 41)
replace yos = 13  if inlist(GRADE_B, 411, 421, 431, 441, 451, 461) | inlist(GRADE_A, 412, 422, 432, 442, 452, 462)
replace yos = 14  if inlist(GRADE_B, 412, 419, 422, 429, 432, 439, 442, 449, 452, 459, 462) | inlist(GRADE_A, 413, 419, 423, 429, 433, 439, 443, 449, 453, 459)
replace yos = 15  if inlist(GRADE_B, 410, 420, 430, 440, 450, 460, 413, 423, 433, 443, 453,19,21,46,48,47,49,11,16,20,29,23,24,25,26,27,51,52,53,54,42,43,44,45) | inlist(GRADE_A, 511, 519, 521, 611, 631, 641, 651,11,16,20,29,23,24,25,26,27,51,52,53,54,42,43,44,45) 
replace yos = 16  if inlist(GRADE_B, 510, 511, 519, 521, 611, 631, 641, 651) | inlist(GRADE_A, 512, 522, 612, 632, 642, 652)
replace yos = 17  if inlist(GRADE_B, 510, 512, 522, 529, 612, 632, 642, 652,22) | inlist(GRADE_A, 523, 529, 613, 633, 643, 649, 653, 661,22)
replace yos = 18  if inlist(GRADE_B, 520, 523, 613, 633, 643, 649, 653, 661) | inlist(GRADE_A, 614, 634, 639, 654, 659)
replace yos = 19  if inlist(GRADE_B, 610, 630, 640, 650, 660, 614, 634, 639, 654, 659) | inrange(GRADE_B, 23, 31) |inrange(GRADE_A, 23, 31) 
replace yos = 20  if inlist(GRADE_B, 711, 719, 731, 739, 751, 759, 712, 719, 732, 739, 752, 759, 761)
replace yos = 21  if inlist(GRADE_B, 710, 730, 750, 615, 712, 732, 752, 760, 761,32,71) | inlist(GRADE_A, 616, 619, 811, 831, 851, 871,32,71)
replace yos = 22  if inlist(GRADE_B, 811, 831, 851, 871) | inlist(GRADE_A, 812, 832, 852, 872)
replace yos = 23  if inlist(GRADE_B, 812, 832, 852, 872) | inlist(GRADE_A, 813, 819, 833, 839, 853, 859, 873)
replace yos = 24  if inlist(GRADE_B, 810, 830, 850, 616, 619, 813, 819, 833, 839, 853, 873,31,33,34) | inlist(GRADE_A, 860, 861, 874,31,33,34) 
replace yos = 25  if inlist(GRADE_B, 860, 861, 874, 879) | inlist(GRADE_A, 875, 879)
replace yos = 29  if inlist(GRADE_B, 870, 875)
replace yos = 9 if OTHEREDU == 1

drop BACHELOR DIP DOCTORAL EDUG ELEM LSEC NEDU OTHEREDU PRI UNI USEC MASTER SEC

lab var yos "Year of schooling"


**Industrial sector
gen indus_label =.
replace indus_label = 1 if industry<1429
replace indus_label = 2 if inrange(industry, 1430, 4000)
replace indus_label = 3 if inrange(industry, 4000, 9901)
label variable indus_label "Industry Sector Label"
label define indusg 1 "Agriculture sector" 2 "Manufacturing sector" 3 "Service sector"
label values indus_label indusg
drop if industry == 99999
drop if industry ==.

**Region
gen region_label =.
replace region_label = 1 if region == 1
replace region_label = 2 if region == 2  
replace region_label = 3 if region == 3  
replace region_label = 4 if region == 4  
replace region_label = 5 if region == 5                                                            
label define regiong 1 "Bangkok" 2 "Central & West (not include BKK)" 3 "North" 4 "North East" 5 "South" 
label values region_label regiong

**area
replace area = 0 if area == 2
replace area = 0 if area == .
label var area "Municipal Area == 1"

**sex
gen sex_label = .
replace sex_label = 1
replace sex_label = 2 if sex == 2
label define sexg 1 "Male" 2 "Female"
label values sex_label sexg  


save "Data\merged.dta", replace

erase Data\merged2011.dta
erase Data\merged2012.dta
erase Data\merged2013.dta
erase Data\merged2014.dta
erase Data\merged2015.dta
erase Data\merged2016.dta



